package com.kingyea.gradle;

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;

import com.kingyea.gradle.extension.Deployer;
import com.kingyea.gradle.extension.RemoteLinuxDeploy;
import com.kingyea.gradle.extension.RemoteWindowsDeploy;
import com.kingyea.gradle.extension.WebServiceServer;
import com.kingyea.gradle.task.LocalDeployTask;
import com.kingyea.gradle.task.RemoteDeployTask;
import com.kingyea.gradle.task.WebServiceDeployTask;

public class KingyeaEsbGradlePlugin implements Plugin<Project> {

	@Override
	public void apply(Project project) {
		project.getExtensions().create("deployer", Deployer.class, new Object[0]);
		project.getExtensions().create("remoteLinux", RemoteLinuxDeploy.class, new Object[0]);
		project.getExtensions().create("remoteWindows", RemoteWindowsDeploy.class, new Object[0]);
		project.getExtensions().create("webServiceServer", WebServiceServer.class, new Object[0]);
		
		LocalDeployTask localDeployTask = project.getTasks().create("deploy", LocalDeployTask.class);
		RemoteDeployTask remoteDeployTask = project.getTasks().create("remoteDeploy", RemoteDeployTask.class);
		remoteDeployTask.dependsOn(localDeployTask);
		
		Task jarTask = project.getTasks().getByName("jar");
		if(jarTask==null) {
			System.out.println("jar task does not exists.");
		}
		
		
		WebServiceDeployTask webServiceDeployTask = project.getTasks().create("webServiceDeploy", WebServiceDeployTask.class);
		webServiceDeployTask.dependsOn(jarTask);
	}

}
